package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.NiubilityBrank;
import com.stylefeng.guns.modular.system.service.INiubilityBrankService;
import com.stylefeng.guns.modular.system.warpper.NiubilityBrankWarpper;

/**
 * 牛股席位追踪控制器
 *
 * @author fengshuonan
 * @Date 2018-06-11 18:19:32
 */
@Controller
@RequestMapping("/niubilityBrank")
public class NiubilityBrankController extends BaseController {

    private String PREFIX = "/system/niubilityBrank/";

    @Autowired
    private INiubilityBrankService niubilityBrankService;

    /**
     * 跳转到牛股席位追踪首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "niubilityBrank.html";
    }

    /**
     * 跳转到添加牛股席位追踪
     */
    @RequestMapping("/niubilityBrank_add")
    public String niubilityBrankAdd() {
        return PREFIX + "niubilityBrank_add.html";
    }

    /**
     * 跳转到修改牛股席位追踪
     */
    @RequestMapping("/niubilityBrank_update/{niubilityBrankId}")
    public String niubilityBrankUpdate(@PathVariable Integer niubilityBrankId, Model model) {
        NiubilityBrank niubilityBrank = niubilityBrankService.selectById(niubilityBrankId);
        model.addAttribute("item",niubilityBrank);
        LogObjectHolder.me().set(niubilityBrank);
        return PREFIX + "niubilityBrank_edit.html";
    }

    /**
     * 获取牛股席位追踪列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String date,String dm,String name) {
    	Page<NiubilityBrank> page = new PageFactory<NiubilityBrank>().defaultPage();
    	List<Map<String, Object>> gdhs = niubilityBrankService.selectMapsByNiubility(page,date,dm,name);
    	page.setRecords((List<NiubilityBrank>) new NiubilityBrankWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增牛股席位追踪
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(NiubilityBrank niubilityBrank) {
        niubilityBrankService.insert(niubilityBrank);
        return SUCCESS_TIP;
    }

    /**
     * 删除牛股席位追踪
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer niubilityBrankId) {
        niubilityBrankService.deleteById(niubilityBrankId);
        return SUCCESS_TIP;
    }

    /**
     * 修改牛股席位追踪
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(NiubilityBrank niubilityBrank) {
        niubilityBrankService.updateById(niubilityBrank);
        return SUCCESS_TIP;
    }

    /**
     * 牛股席位追踪详情
     */
    @RequestMapping(value = "/detail/{niubilityBrankId}")
    @ResponseBody
    public Object detail(@PathVariable("niubilityBrankId") Integer niubilityBrankId) {
        return niubilityBrankService.selectById(niubilityBrankId);
    }
}
